﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SkynetMaster.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Skynet.BusinessEntities.ExamCategory>>" %>


<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>        
    <script src="http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjaxCore.js" type="text/javascript"></script>    
    <script src="http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjaxSerialization.js" type="text/javascript"></script>        
    <script src="http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjaxNetwork.js" type="text/javascript"></script>    
    <script src="http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjaxWebServices.js" type="text/javascript"></script>    
    <script src="/Services/SkynetService.asmx/js" type="text/javascript"></script>

    <script src="<%= Url.Content("~/Scripts/MicrosoftAjax.debug.js") %>"></script>
    <script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js") %>"></script>
    <script src="<%= Url.Content("~/Scripts/MicrosoftMvcValidation.js") %>"></script>
    
    
    
    

    
    
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	CategoriesAsync
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
         
     <script type="text/javascript">
        $(document).ready(function(){
            $("#btnSearch").click(function(){
                $.post("<%= Url.Action("CategoriesJson") %>" , function(data) {
                        $("#cbCategories").empty();
                        $.each(data, function(i, item) {
                            $("#cbCategories").append("<option id='" + item.Id +"'>" + item.Description + "</option>");
                        });
                });            
            });
        });       
            

        
        function loadServCategories()
        {
            Skynet.MVCWebSite.Services.SkynetService.DefaultCategories(OnSuccessDefaultCategories);
            
        }
        function OnSuccessDefaultCategories(result){
            $("#cbSerCategories").empty();
            $.each(result, function(i, item) {
                $("#cbSerCategories").append("<option id='" + item +"'>" + item + "</option>");
            });
        }        
        function loadAjaxCategories(callcontext)
        {
            var response = callcontext.get_data();
            var categories = eval(response);


            $("#cbAjaxCategories").empty();
            $.each(categories, function(i, item) {
                $("#cbAjaxCategories").append("<option id='" + item.Id +"'>" + item.Description + "</option>");
            });
        
        }
      </script>
    <h2>CategoriesAsync</h2>
    <input type="button"  id="btnSearch"  value="Load"/>        
    <select id="cbCategories"></select> 
    <br />
    <input type="button"  id="btnServSearch"  value="Load" onclick="return loadServCategories();"/>
    <select id="cbSerCategories"></select> 
    <br />
    <%=   Ajax.ActionLink("load categories", "CategoriesJson", new AjaxOptions() { OnSuccess = "loadAjaxCategories", HttpMethod = "Post", LoadingElementId = "WaitPanel" })%>
    <select id="cbAjaxCategories"></select> 
    <br/>
    <%= Ajax.ActionLink("load categories panel", "CategoriesString", new AjaxOptions() { HttpMethod = "Post", UpdateTargetId = "targetPanel", LoadingElementId = "WaitPanel" })%>
    
    <div id="targetPanel">

    </div>

    <div id="WaitPanel" style="display:none;">
        <img alt="loading" src='<%= Url.Content("~/Images/ajax-loader.gif")%>' />        
    </div>

</asp:Content>

